package com.example.medicalzb.controller;

import com.example.medicalzb.param.MedicalPolicyParam;
import com.example.medicalzb.service.MedicalPolicyService;
import com.example.medicalzb.util.Msg;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.RolesAllowed;

@RestController
@RequestMapping("/api/medical_policys")
@Api(tags = "医保政策控制器类")
@CrossOrigin
public class MedicalPolicyController {
    @Autowired
    private MedicalPolicyService medicalPolicyService;

    //查询医保政策信息
    @GetMapping(value = "")
    public Msg getMedicalPolicyWithPage(MedicalPolicyParam medicalPolicyParam){
        return medicalPolicyService.getMedicalPolicyWithPage(medicalPolicyParam);
    }

    //添加医保政策信息
    @PostMapping(value = "")
    @RolesAllowed({"1"})
    public Msg saveMedicalPolicy(@RequestBody MedicalPolicyParam medicalPolicyParam){
        return medicalPolicyService.saveMedicalPolicy(medicalPolicyParam);
    }

    //修改医保政策信息
    @PutMapping(value = "/{id}")
    @RolesAllowed({"1"})
    public Msg updateMedicalPolicy(@PathVariable("id") Long id, @RequestBody MedicalPolicyParam policyParam){
        if (policyParam.getTitle() == null || policyParam.getTitle().equals("")){
            return Msg.fail().mess("标题不能为空");
        }
        if (policyParam.getMessage() == null || policyParam.getMessage().equals("")){
            return Msg.fail().mess("内容不能为空");
        }
        if (policyParam.getCityId() == null){
            return Msg.fail().mess("城市不能为空");
        }
        return medicalPolicyService.updateMedicalPolicy(id,policyParam);
    }

    //删除医保政策
    @RolesAllowed({"1"})
    @DeleteMapping("/{id}")
    public Msg deleteMedicalPolicy(@PathVariable("id") Long id){
        return medicalPolicyService.deleteMedicalPolicy(id);
    }

}
